#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>

#define BUFF_SIZE 1024

int main()
{
    struct sockaddr_in sock_addr;
    memset(&sock_addr, 0, sizeof(sock_addr));
    

    sock_addr.sin_family = AF_INET;
    sock_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
    sock_addr.sin_port = htons(1234);
    

    char sendBuffer[BUFF_SIZE] = {0};
    char recvBuffer[BUFF_SIZE] = {0};
    while (1)
    {
        int sock = socket(AF_INET, SOCK_STREAM, 0);
        connect(sock, (struct sockaddr*)&sock_addr, sizeof(sock_addr));
        printf("Please input your message: ");
        // scanf("%s", sendBuffer);
        fgets(sendBuffer, BUFF_SIZE, stdin);
        send(sock, sendBuffer, strlen(sendBuffer), 0);

        recv(sock, recvBuffer, BUFF_SIZE, 0);
        printf("Message from server: %s", recvBuffer);
        close(sock);
        memset(sendBuffer, 0, BUFF_SIZE);
        memset(recvBuffer, 0, BUFF_SIZE);
    }

    return 0;
}